// TypeScript type definitions for the workflow designer
export interface FlowConfig {
  nodeName: string
  error: boolean
  type: number // 节点类型
  priorityLevel: string
  settype: string
  selectMode: string
  selectRange: string
  directorLevel: string
  examineMode: number
  noHanderAction: string
  examineEndDirectorLevel: string
  ccSelfSelectFlag: string
  conditionList: []
  nodeUserList: []
  childNode: FlowConfig // 子节点
  conditionNodes: FlowConfig[] // 条件节点
}

export interface WorkflowConfiguration {
  id: number
  basicInfo: import('/@/components/BasicInfo/types').BasicInfo
  formConfig: import('/@/components/FormDesigner/types').FormConfig
  flowConfig: FlowConfig
  status?: 'enabled' | 'disabled'
  metadata: {
    version: string
    exportTime: string
    checksum?: string
  }
}

// 工作流实例相关类型
export interface WorkflowInstance {
  id: number
  workflowId: number
  workflowName: string
  status: 'running' | 'complete' | 'reject'
  variables: Record<string, any>
  formConfig: import('/@/components/FormDesigner/types').FormConfig
  currentNodeId: number
  currentNodeName: string
	updateTime: Date
	modifierId: number
	modifier: string
  createTime: Date
	creatorId: number
	creator: string
  deleted: boolean
	deleteTime: Date
}

// 节点用户
export type NodeUser = {
	type: number
	targetId: number
	name: string
}

// 单节点
export interface SingleNode {
	workflowInstanceId: number
	nodeName: string
	type: number
	nodeUserList: NodeUser[]
	examineMode: number
	condition: string
}

// 工作流实例详情
export interface WorkflowInstanceDetail{
  workflowInstance: WorkflowInstance
  nodeActionHistories: NodeActionHistory[]
  // 后续节点
  subsequentNodes: Array<SingleNode[]>
}

// 节点审批人
export interface NodeAssignee {
	type: number
	name: string
	targetId: number
	nodeId: number
	workflowInstanceId: number
}

// 节点操作人
export interface NodeOperator {
	nodeId: number
	nodeName: string
	workflowInstanceId: number
	operator: string
	operatorId: number
}

export interface NodeCcUser {
  userName: string // 姓名
  userId: number // 用户ID
  source: string // 来源
  sourceId: number // 来源ID
}

// 节点操作历史
export interface NodeActionHistory {
	id: number
  createTime: Date
  updateTime: Date
  workflowInstanceId: number
  nodeId: number
  nodeName: string
  nodeType: number
  type: 0 | 1 | 2 | 4 | 12 | 13 | 14 | 15 | 99 // 0 开始操作 1 或签操作 12 会签操作 13 评论操作 14 拒绝操作 15 转办 2 抄送操作 4 条件操作 99 取消申请
  status: 'approving' | '' | 'rejected' | 'completed' // 为空时表示完成,approving 只有审批节点有
  examineMode: number
  actionInfo: {
    assignee: NodeAssignee[]
    operator: NodeOperator[]
    ccUser: NodeCcUser[]
    fromAssignees: NodeAssignee[]
    toAssignees: NodeAssignee[]
    reason: string
  }
	comment: string
}